package com.hex.ds.hdtp.core.web.data.table.controller;

import com.hex.bigdata.hbda.annotation.Log;
import com.hex.ds.hdtp.core.app.common.page.dto.PageDto;
import com.hex.ds.hdtp.core.app.data.table.dto.request.TableTransferTaskRequestDto;
import com.hex.ds.hdtp.core.app.data.table.service.ITableTransferTaskService;
import com.hex.ds.hdtp.core.web.common.page.PageVo;
import com.hex.ds.hdtp.core.web.common.page.converter.IPageVoAndPageDtoConverter;
import com.hex.ds.hdtp.core.web.data.table.converter.ITableTransferTaskVoConverter;
import com.hex.ds.hdtp.core.web.data.table.vo.TableTransferTaskVo;
import com.hex.ds.hdtp.core.web.data.table.vo.query.TableTransferTaskQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Package com.hex.ds.hdtp.core.web.data.table.controller
 * @ClassName TableTransferTaskController
 * @Description 表迁移任务-WEB接口
 * @Author Wang zhihao
 * @Date 2023/8/8 18:52
 * @Version v1.0
 **/
@Slf4j
@RestController
@Api(tags = "01-表迁移：任务")
@RequestMapping("/api/data/table/task")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TableTransferTaskController {

    private final ITableTransferTaskService tableTransferTaskService;

    private final ITableTransferTaskVoConverter converter;

    private final IPageVoAndPageDtoConverter pageVoAndPageDtoConverter;

    /**
     * @param tableTransferTaskQueryVo
     * @param pageVo
     * @Method queryListByPage
     * @Param
     * @Return org.springframework.http.ResponseEntity
     * @Description 表迁移任务-分页查询
     * @Author Wang zhihao
     * @Date 2023/8/8 18:53
     * @Version V1.0
     */
    @GetMapping
    @ApiOperation("表迁移任务-分页查询")
    public ResponseEntity queryListByPage(TableTransferTaskQueryVo tableTransferTaskQueryVo, PageVo pageVo) {
        log.debug("进入到【TableTransferTaskController.queryListByPage】方法,参数：{}" + tableTransferTaskQueryVo.toString());
        final PageDto pageDto = pageVoAndPageDtoConverter.toPageDto(pageVo);
        TableTransferTaskRequestDto requestDto = converter.toRequestDtoByQuery(tableTransferTaskQueryVo);
        return ResponseEntity.ok(tableTransferTaskService.queryListByPage(requestDto, pageDto));
    }

    /**
     * @param tableTransferTaskVo
     * @Method add
     * @Param
     * @Return org.springframework.http.ResponseEntity
     * @Description 表迁移任务-新增
     * @Author Wang zhihao
     * @Date 2023/8/9 10:41
     * @Version V1.0
     */
    @Log("表迁移任务-新增")
    @PostMapping
    @ApiOperation("表迁移任务-新增")
    public ResponseEntity add(@RequestBody TableTransferTaskVo tableTransferTaskVo) {
        log.info("进入到【TableTransferTaskController.add】方法,参数：{}", tableTransferTaskVo.toString());
        String pkId = tableTransferTaskService.addWithBackId(converter.toRequestDto(tableTransferTaskVo));
        return ResponseEntity.ok(pkId);
    }

    /**
     * @param tableTransferTaskVo
     * @Method update
     * @Param
     * @Return org.springframework.http.ResponseEntity
     * @Description 表迁移任务-更新
     * @Author Wang zhihao
     * @Date 2023/8/9 10:41
     * @Version V1.0
     */
    @PutMapping
    @ApiOperation("表迁移任务-更新")
    public ResponseEntity update(@RequestBody TableTransferTaskVo tableTransferTaskVo) {
        log.info("进入到【TableTransferTaskController.update】方法,主键：{}", tableTransferTaskVo.getPkId());
        tableTransferTaskService.modifyById(converter.toRequestDto(tableTransferTaskVo));
        return ResponseEntity.ok("更新成功");
    }

    /**
     * @param pkIds
     * @Method delete
     * @Param
     * @Return org.springframework.http.ResponseEntity
     * @Description 表迁移任务-批量删除
     * @Author Wang zhihao
     * @Date 2023/8/9 10:42
     * @Version V1.0
     */
    @Log("表迁移任务-批量删除")
    @DeleteMapping(value = {"/{pkIds}"})
    @ApiOperation("表迁移任务-批量删除")
    public ResponseEntity delete(@PathVariable("pkIds") @NotNull List<String> pkIds) {
        log.info("进入【TableTransferTaskController.delete】方法,参数：" + pkIds);
        tableTransferTaskService.batchRemoveById(pkIds);
        return ResponseEntity.ok("删除成功");
    }

    /**
     * @param pkId
     * @Method contrast
     * @Param
     * @Return org.springframework.http.ResponseEntity
     * @Description 表迁移任务-迁移
     * @Author Wang zhihao
     * @Date 2023/8/10 14:59
     * @Version V1.0
     */
    @Log("表迁移任务-迁移")
    @PutMapping(value = {"/transfer/{pkId}"})
    @ApiOperation("表迁移任务-迁移")
    public ResponseEntity transfer(@PathVariable("pkId") @NotNull String pkId) {
        log.info("进入【TableTransferTaskController.transfer】方法, 主键：{}", pkId);
        tableTransferTaskService.transfer(pkId);
        return ResponseEntity.ok("操作成功");
    }

}
